
package com.baidu.utils;

import java.util.ArrayList;
import java.util.List;

public class Pages {
    private Integer currentPage;//当前页
    private Integer totalCount;//总记录数
    private Integer cp;
    private Integer pageSize;//页面容量

    private Integer totalPage;//总页数
    private Integer prePage;//上一页
    private Integer nextPage;//下一页

    private List<Integer> pageList;//保存页码
    public Integer getCp() {
        if (getCurrentPage()==1) {
            cp=0;
        }else {
            cp = (getCurrentPage()-1) * getPageSize();
        }
        return cp;
    }
    public void setCp(Integer cp) {
        this.cp = cp;
    }
    //保存页码
    public List<Integer> getPageList() {
        pageList = new ArrayList<>();
        for (int i=1;i<=getTotalPage();i++){
            System.out.println("i:"+i+"p:"+getTotalPage());
            pageList.add(i);
        }
        return pageList;
    }

    public void setPageList(List<Integer> pageList) {
        this.pageList = pageList;
    }


    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    //计算总页数
    public Integer getTotalPage() {
        System.out.println("hhhhh"+getTotalCount()+"sadadas"+getPageSize());
        if(getTotalCount()<=getPageSize()){//整除
            totalPage=1;
        }else if (getTotalCount()%getPageSize()==0){
            totalPage=getTotalCount()/getPageSize();
        }else {//不能整除
            totalPage=getTotalCount()/getPageSize()+1;
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    //计算上一页
    public Integer getPrePage() {
        if (getCurrentPage()<=1){//已经在首页
            prePage=1;
        }else {
            prePage=getCurrentPage()-1;
        }
        return prePage;
    }

    public void setPrePage(Integer prePage) {
        this.prePage = prePage;
    }

    //计算下一页
    public Integer getNextPage() {
        if (getCurrentPage()>=getTotalPage()){
            nextPage=getTotalPage();
        }else {
            nextPage=getCurrentPage()+1;
        }
        return nextPage;
    }

    public void setNextPage(Integer nextPage) {
        this.nextPage = nextPage;
    }
}
